/**
 * Copyright &copy; 2016-2017 <a href="http://git.oschina.net/whoamien/backend_management">Backend Management</a> All rights reserved.
 */
package com.xw.app.dao;

import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.xw.app.model.SysMenu;
import com.xw.framework.base.dao.BaseDAO;

/**
 * The Interface SysMenuDAO.
 *
 * @author Xi Wei
 */
@Repository
public interface SysMenuDAO extends BaseDAO<SysMenu, Long> {

	/**
	 * Find by system id and parent is null.
	 *
	 * @param systemId the system id
	 * @return the list
	 */
	@Query("select a from SysMenu a where (a.system.id is null or a.system.id = ?1) and a.parent.id is null order by a.menuOrder")
	public List<SysMenu> findBySystemIdAndParentIsNull(Long systemId);
	
	/**
	 * Find by system id and menu level less than equal.
	 *
	 * @param systemId the system id
	 * @param menuLevel the menu level
	 * @return the list
	 */
	@Query("select a from SysMenu a where (a.system.id is null or a.system.id = ?1) and a.menuLevel <= ?2 order by a.menuOrder")
	public List<SysMenu> findBySystemIdAndMenuLevelLessThanEqual(Long systemId,int menuLevel);
	
	/**
	 * Find by system id and menu type in.
	 *
	 * @param systemId the system id
	 * @param types the types
	 * @return the list
	 */
	@Query("select a from SysMenu a where (a.system.id is null or a.system.id = ?1) and menuType in ?2 order by a.menuOrder")
	public List<SysMenu> findBySystemIdAndMenuTypeIn(Long systemId,Integer... types);
}
